package etcd

import (
	"github.com/sirupsen/logrus"
	clientv3 "go.etcd.io/etcd/client/v3"
	"strings"
	"time"
)

var (
	etcdClient *clientv3.Client
	Config     etcdConfig
)

type etcdConfig struct {
	Address string `ini:"address"`
	LogKey  string `ini:"log_key"`
}

type logPath struct {
	Path  string `json:"path"`
	Topic string `json:"topic"`
}

func InitConfig() error {
	var err error
	etcdClient, err = clientv3.New(clientv3.Config{
		Endpoints:   strings.Split(Config.Address, ","),
		DialTimeout: time.Second * 5,
	})
	if err != nil {
		logrus.Error("etcd: connect is failed!", err)
		return err
	}
	time.Sleep(time.Second * 4)

	return nil
}
